package h0826;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

/**
 * @author 不知名帅哥
 * @version 1.0
 * @description 全排列
 * @date 2024/8/26 21:18
 */
public class AllPermutations {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] nums = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        List<List<Integer>> res = getRes(nums);
        System.out.println(res);
    }

    private static List<List<Integer>> getRes(int[] nums) {
        List<List<Integer>> ans = new ArrayList<>();
        backTrack(ans, new ArrayList<>(), nums);
        return ans;
    }

    private static void backTrack(List<List<Integer>> ans, ArrayList<Integer> temp, int[] nums) {
        if (temp.size() == nums.length) {
            ans.add(new ArrayList<>(temp));
            return;
        }
        for (int i = 0; i < nums.length; i++) {
           if (!temp.contains(nums[i])){
               temp.add(nums[i]);
               backTrack(ans, temp, nums);
               temp.remove(temp.size()-1); //回溯
           }
        }
    }
}
